#include "pixmapbutton.h"
#include <QBitmap>
PixmapButton::PixmapButton(QWidget *parent)
	: QToolButton(parent)
{
}

PixmapButton::PixmapButton(const QString &fileName, QWidget *parent)
	: QToolButton(parent)
	, _icon(QIcon(fileName))
{
	const QPixmap &pixmap = QPixmap(fileName);
	setSize(pixmap.size());
	setMask(pixmap.mask());
	setIcon(_icon);
	//setFlat(true);
	setFocusPolicy(Qt::NoFocus);
}

PixmapButton::PixmapButton(const QIcon &icon, QWidget *parent)
	: QToolButton(parent)
	, _icon(QIcon(icon))
{
	setIcon(_icon);
	//setFlat(true);
	setFocusPolicy(Qt::NoFocus);
}

PixmapButton::~PixmapButton()
{
}

void PixmapButton::addIconPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
{
	_icon.addPixmap(pixmap, mode, state);
}

void PixmapButton::addIconPixmap(const QString &pixmap, QIcon::Mode mode, QIcon::State state)
{
	addIconPixmap(QPixmap(pixmap), mode, state);
}

void PixmapButton::setSize(const QSize &size)
{
	setIconSize(size);
	//setFixedSize(size);
	resize(size);
}


CheckablePixmapButton::CheckablePixmapButton(const QString &icon1, const QString &icon2, QWidget *parent)
	: PixmapButton(parent)
{
	const QPixmap &pixmap = QPixmap(icon1);
	setSize(pixmap.size());
	//setMask(pixmap.mask());
	setCheckable(true);
	//setFlat(true);

	_icon = QIcon(pixmap);
	_icon.addPixmap(QPixmap(icon2), QIcon::Normal, QIcon::On);
	setIcon(_icon);
}
